// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
struct node
{
	int l,r;
};
signed main()
{
	int t=1;
	cin>>t;
	while(t--)
	{
		int n,c=0;
		bool f=0;
		cin>>n;
		vector<int> v(n+1),w;
		vector<node> j;
		for(int i=1;i<=n;i++)
		{
			cin>>v[i];
			if(v[i]==0)
			{
				f=1;
				w.push_back(i);
				c++;
			}
		}
		if(!f)
		{
			cout<<1<<endl;
			cout<<1<<" "<<n<<endl;
		}
		else
		{
			while(1)
			{
				auto it=find(v.begin()+1, v.end(), 0);
				if(it==v.end())break;
				node z;
				if(it+1!=v.end()&&*(it+1))
				{
					z.l=it-v.begin();
					z.r=z.l+1;
					v.erase(it);
				}
				else if(it+1==v.end())
				{
					z.l=it-v.begin()-1;
					z.r=z.l+1;
					v.erase(it);
				}
				else
				{
					z.l=it-v.begin();
					z.r=z.l+1;
					v.erase(it+1);
					v.erase(it);
					v.insert(it,1);
				}
				j.push_back(z);
			}
			int m=j.size();
			cout<<m+1<<endl;
			for(int i=0;i<m;i++)
			{
				cout<<j[i].l<<" "<<j[i].r<<endl;
			}
			cout<<1<<" "<<v.size()-1<<endl;
		}
	}
	return 0;
}
